<template>
	<view class="GroupOrder">
		<view class="GroupOrderBox">
			<!-- 基础信息开始 -->
			<view class="BasicsBox">
				<view class="Basicstitle">基础信息</view>
				<view class="Basics">
					<picker mode="selector" :range="cateList" @change="choiceCate" range-key="name" :value="cateIndex">
						<view class="BasicsItem">
							<view class="BasicsName">商户分类</view>
							<view class="Basics_R">
								<view class="Basicstype">{{cateIndex!=-1?cateList[cateIndex].name:"请选择"}}</view>
								<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
							</view>
						</view>
					</picker>
					<view class="BasicsItem" @click="toAddStore">
						<view class="BasicsName">使用门店</view>
						<view class="Basics_R" style="width: calc(100% - 112upx);">
							<view class="Basicstype" style="width: calc(100% - 32upx);text-align: right;">
								<text v-for="(item,index) in storeData" :key="index" v-if="storeData.length>0&&index<3">{{item.name}}<text v-if="index!=2">,</text><text v-if="storeData.length>3&&index==2">...</text></text>
								<text v-if="storeData.length==0">请选择</text>
							</view>
							<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
						</view>
					</view>
				</view>
			</view>
			<!-- 基础信息结束 -->
			<!-- 商品信息开始 -->
			<view class="commodityBox">
				<view class="commoditytitle">商品信息</view>
				<view class="commodityInfo">
					<view class="commodityNameBox">
						<view class="commodityName">团单名称</view>
						<view class="commodity_R">
							<input type="text" placeholder="请输入团单名称" v-model="formData.name" style="text-align: right;font-size: 24upx;" />
						</view>
					</view>
					<view class="service">
						<text>服务项目</text>
						<text style="color: red;" @click="addProject">添加项目+</text>
					</view>
					<view class="uploadBox">
						<!-- <u-upload :action="action" :file-list="fileList" ></u-upload> -->
						<view class="tcItem" v-for="(item,index) in tcList" :key="index">
							<view class="tcItemT">
								<text>套餐名称</text>
								<input type="text" placeholder="请输入套餐名称" v-model="item.name" />
								<text @click="addCon" :data-index="index">添加内容+</text>
								<text @click="delTc" :data-index="index">删除</text>
							</view>
							<view class="tcItemB">
								<view class="tcItemBItem" v-for="(pitem,pindex) in item.conList" :key="pindex">
									<input type="text" placeholder="例:xxx鱼排一份" v-model="pitem.name" />
									<input type="number" placeholder="请输入价格" v-model="pitem.price" />
									<text @click="delCon" :data-pindex="pindex" :data-index="index">删除</text>
								</view>
							</view>
						</view>
					</view>
					<view class="priceBox">
						<view class="priceName">团单售价</view>
						<view class="price_R">
							<input type="number" placeholder="请输入金额" v-model="formData.money" @blur="changeGroup" />元
						</view>
					</view>
					<view class="priceBox">
						<view class="priceName" style="width: 140upx;">推广服务费</view>
						<view class="price_R" style="width: calc(100% - 140upx);">
							<input type="number" placeholder="请输入金额" v-model="formData.user_commission_money" @blur="changeGroupMoney" :disabled="!formData.money" />元
						</view>
					</view>

					<view class="tips" style="display: flex;align-items: center;" @click="toIntro">
						<view>
							订单结算金额=商品售价-平台服务费-推广服务费 当前商品结算价{{settleMoney}}元
						</view>
						<image src="/static/index/intro_red.png" style="width: 28upx;height: 28upx;margin-left: 6upx;"></image>
						<!-- 推广服务费:{{reducePrice}}元{{price>0?reducePrice/price*100:0}}%,用户分享此团单后通过分享链接购买获得的佣金(商户结算费用=售价-分享价-手续费) -->
					</view>
					<view class="Head-diagram">商品头图</view>
					<view class="tips_text">商品主图必须上传，图片比例为1:1，图片大小不超过5M.</view>
					<view class="uploadBoxs" @click="uploadHeadImg" v-if="!headImg">
						<image src="../../static/mine/photo.png" class="uploadIcon"></image>
					</view>
					<view class="uploadBoxs" @click="uploadHeadImg" style="border: none;background-position: center;background-size: cover;" :style="{'background-image':'url('+getImage(headImg)+')'}" v-if="headImg"></view>
					<!-- <image class="uploadBoxs" @click="uploadHeadImg" style="border: none;" :src="getImage(headImg)" v-if="headImg"></image> -->
					<view class="Head-diagram" style="margin-top: 16upx;">商品展示图</view>
					<view class="tips_text">图片比例为16:9，图片大小不超过5M.</view>
					<view style="display: flex;flex-wrap: wrap;" class="uploadProImg">
						<view class="uploadBoxs" @click="uploadProImg">
							<image src="../../static/mine/photo.png" class="uploadIcon"></image>
						</view>
						<view v-for="(item,index) in proImg" :key="index">
							<view class="imgBoxWrap" :style="{'background-image':'url('+getImage(item)+')'}"></view>
							<view style="line-height: 60upx;line-height: 60upx;text-align: center;color: red;font-size: 28upx;" :data-index="index" @click="delImg">删除</view>
						</view>
					</view>
					
					<view class="commodityNameBox">
						<view class="commodityName">图文介绍</view>
						<view class="commodity_R" @click="toGraphicIntroduction">
							<view class="commoditytext">编辑</view>
							<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
						</view>
					</view>
					<view class="commodityNameBox" style="align-items: flex-start;">
						<view class="commodityName">补充信息</view>
						<view class="commodity_R" style="width: calc(100% - 200upx);">
							<textarea placeholder="请输入补充信息" style="height: 200upx;text-align: right;" v-model="formData.remind" />
						</view>
					</view>
				</view>
			</view>
			<!-- 商品信息结束 -->
			<!-- 购买须知开始 -->
			<view class="NoticeBox">
				<view class="Noticetitle">购买须知</view>
				<view class="NoticeInfo">
					<view class="stockBox">
						<view class="stocktitle">库存限制</view>
						<view class="switchBox">
							<u-switch v-model="stockchecked" active-color="#FFAC3F" @change="stockswitchBtn"></u-switch>
						</view>
					</view>
					<view class="stockBox" v-if="stockchecked">
						<view class="stocktitle">库存数量</view>
						<input type="number" style="text-align: right;" placeholder="请输入库存数量" v-model="stockNum" />
					</view>

					<view class="validityBox" style="display: block;">
						<view style="display: flex;align-items: center;justify-content: space-between;">
							<view class="validitytitle">团单有效期</view>
							<view class="radioBox">
								<u-radio-group v-model="Rdaiovalue">
									<u-radio @change="radioChange" shape="square" active-color="#FFAC3F"
										v-for="(item, index) in RdaioList" :key="index" :name="item.name" :checked="item.checked">
										{{item.name}}
									</u-radio>
								</u-radio-group>
							</view>
						</view>
						<view class="ordertitmeBox" style="padding-right: 24upx;padding-bottom: 0;" v-if="Rdaiovalue=='相对时间'">
							<view class="orderName">下单后有效时间</view>
							<view class="ordertitme" style="display: flex;align-items: center;">
								<input type="number" style="text-align: right;" v-model="days" />
								天
							</view>
						</view>
						<view class="ordertitmeBox" style="padding-right: 24upx;padding-bottom: 0;" v-if="Rdaiovalue=='指定时间'">
							<view class="orderName">到期时间</view>
							<picker mode="date" @change="selectOutTime" v-model="outTime" :value="outTime">
								<view class="ordertitme" style="display: flex;align-items: center;">
									{{outTime?outTime:"请选择"}}
								</view>
							</picker>
							
						</view>
					</view>

					<view class="validityBox">
						<view class="validitytitle">上架时间</view>
						<view class="radioBox">
							<u-radio-group v-model="ShelfValue">
								<u-radio @change="radioShelf" shape="square" active-color="#FFAC3F"
									v-for="(item, index) in ShelfTime" :key="index" :name="item.name">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="OffshelftimeBox" v-if="ShelfValue=='指定时间'">
						<view class="OffshelftimeName">上架时间</view>
						<picker mode="date" @change="putOnTheShelf" v-model="putOnTheShelfTime">
							<view class="Offshelftime_R">
								<view class="Offshelftimetext">{{putOnTheShelfTime?putOnTheShelfTime:"请选择"}}</view>
								<view style="margin-left: 8upx;">
									<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
								</view>
							</view>
						</picker>
					</view>
					<view class="validityBox">
						<view class="validitytitle">下架时间</view>
						<view class="radioBox">
							<u-radio-group v-model="OffshelfValue">
								<u-radio @change="radioOffshelftime" shape="square" active-color="#FFAC3F" v-for="(item, index) in Offshelftime" :key="index"
									:name="item.name">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="OffshelftimeBox" v-if="OffshelfValue=='指定时间'">
						<view class="OffshelftimeName">下架时间</view>
						<picker mode="date" @change="offTheShelf" v-model="offTheShelfTime" :end="endTimes">
							<view class="Offshelftime_R">
								<view class="Offshelftimetext">{{offTheShelfTime?offTheShelfTime:"请选择"}}</view>
								<view style="margin-left: 8upx;">
									<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
								</view>
							</view>
						</picker>
					</view>
					<view class="stockBox">
						<view class="stocktitle">使用时间限制</view>
						<view class="switchBox">
							<u-switch v-model="limitchecked" active-color="#FFAC3F" @change="limitswitchBtn"></u-switch>
						</view>
					</view>
					<view class="OffshelftimeBox" v-if="limitchecked">
						<view class="OffshelftimeName">使用时间段</view>
						<picker mode="multiSelector" :range="timeList" @change="timSlotChange" v-model="timSlot" :value="timeArrs">
							<view class="Offshelftime_R">
								<view class="Offshelftimetext">{{timeArrs.length>0?(timeList[0][timeArrs[0]]+'--'+timeList[1][timeArrs[1]]):"请选择"}}</view>
								<view style="margin-left: 8upx;">
									<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
								</view>
							</view>
						</picker>
					</view>
					<view class="stockBox">
						<view class="stocktitle">节假日可用</view>
						<view class="switchBox">
							<u-switch v-model="holiday" active-color="#FFAC3F" @change="holidaySwitchBtn">
							</u-switch>
						</view>
					</view>
					<view class="stockBox">
						<view class="stocktitle">休息日可用</view>
						<view class="switchBox">
							<u-switch v-model="restDay" active-color="#FFAC3F" @change="restDaySwitchBtn">
							</u-switch>
						</view>
					</view>
					<view class="stockBox">
						<view class="stocktitle">单人购买量限制</view>
						<view class="switchBox">
							<u-switch v-model="Singlechecked" active-color="#FFAC3F" @change="SingleswitchBtn">
							</u-switch>
						</view>
					</view>
					<view class="stockBox" v-if="Singlechecked">
						<view class="stocktitle">单人购买量限制数量</view>
						<input type="number" style="text-align: right;" placeholder="请输入单人购买量限制数量" v-model="buyNum" />
					</view>
					<view class="stockBox">
						<view class="stocktitle">需要预约</view>
						<view class="switchBox">
							<u-switch v-model="makechecked" active-color="#FFAC3F" @change="makeswitchBtn"></u-switch>
						</view>
					</view>
					<!-- <view class="OffshelftimeBox">
						<view class="OffshelftimeName">使用人数</view>
						<view class="Offshelftime_R">
							<view class="Offshelftimetext">不限人数</view>
							<view style="margin-left: 8upx;">
								<u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon>
							</view>
						</view>
					</view> -->
					<view class="validityBox">
						<view class="validitytitle">使用人数</view>
						<view class="radioBox">
							<u-radio-group v-model="useNum">
								<u-radio @change="useNumChange" shape="square" active-color="#FFAC3F"
									:checked="item.checked" v-for="(item, index) in useNumList" :key="index"
									:name="item.name" :disabled="item.disabled">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="stockBox" v-if="useNum=='指定人数'">
						<view class="stocktitle">指定使用人数</view>
						<input type="number" style="text-align: right;" placeholder="请输入使用人数" v-model="userNum" />
					</view>
					<view class="OffshelftimeBox">
						<view class="OffshelftimeName">与其它优惠同享</view>
						<view class="Offshelftime_R">
							<u-switch v-model="discountBy" active-color="#FFAC3F" @change="discountByBtn"></u-switch>
						</view>
					</view>
					<view class="OffshelftimeBox">
						<view class="OffshelftimeName">结算方式</view>
						<view class="Offshelftime_R">
							<view class="Offshelftimetext">统一结算</view>
							<!-- <u-icon name="arrow-right" color="#BFBFBF" size="25"></u-icon> -->
						</view>
					</view>
				</view>
			</view>
			<!-- 购买须知结束 -->
			<view class="SubmitBox">
				<view class="RadioBox">
					<label class="radio" @click="selectRadio">
						<radio value="" :checked="Radiochecked" /><text>我已阅读并且同意<text
								style="color: #2878ff;text-decoration: underline;" @click="toXy">《商户服务协议》</text></text>
					</label>
				</view>
				<view class="SubmitBtn" @click="submit">提交</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				BasicsList: [{
					name: "商户分类",
					text: "美发"
				}, {
					name: "适用门店",
					text: "请选择"
				}], //基础信息
				action: 'http://www.example.com/upload',
				discountBy:true,
				timeArrs:[],
				endTimes:"",
				timSlot:"",
				settleMoney:0,
				timeList:[
					[
						"00:00",
						"01:00",
						"02:00",
						"03:00",
						"04:00",
						"05:00",
						"06:00",
						"07:00",
						"08:00",
						"09:00",
						"10:00",
						"11:00",
						"12:00",
						"13:00",
						"14:00",
						"15:00",
						"16:00",
						"17:00",
						"18:00",
						"19:00",
						"20:00",
						"21:00",
						"22:00",
						"23:00"
					],
					[
						"00:00",
						"01:00",
						"02:00",
						"03:00",
						"04:00",
						"05:00",
						"06:00",
						"07:00",
						"08:00",
						"09:00",
						"10:00",
						"11:00",
						"12:00",
						"13:00",
						"14:00",
						"15:00",
						"16:00",
						"17:00",
						"18:00",
						"19:00",
						"20:00",
						"21:00",
						"22:00",
						"23:00"
					]
				],
				fileList: [], //图片列表
				HeadImageList: [], //商品头图
				price: 0, //团单售价
				stockchecked: false, //库存滑块
				richData:{},
				formData:{
					name:"",
					money:"",
					user_commission_money:"",
					remind:""
				},
				stockNum:"",
				days:"",
				buyNum:"",
				useNum:"",
				userNum:"",
				RdaioList: [{
					name: '相对时间',
					disabled: false
				}, {
					name: '指定时间',
					disabled: false
				}], //单选框
				useNumList: [{
					name: '不限人数',
					disabled: false
				}, {
					name: '指定人数',
					disabled: false
				}], //单选框
				ShelfTime: [{
					name: '提交成功立即上架',
					disabled: false
				}, {
					name: '指定时间',
					disabled: false
				}], //上架时间
				Offshelftime: [{
					name: '自动延期保持上架',
					disabled: false
				}, {
					name: '指定时间',
					disabled: false
				}], //下架时间
				Rdaiovalue: '', //单选框选择的值
				ShelfValue: '提交成功立即上架',
				OffshelfValue: '自动延期保持上架',
				limitchecked: false, //时间限制滑块
				Singlechecked: false, //单人购买
				makechecked: true, //预约
				Radiochecked: false,
				reducePrice: 0,
				tcList: [],
				outTime:"",
				outTimeIndex:0,
				putOnTheShelfTime:"",
				offTheShelfTime:"",
				timeSlot:"",
				holiday:true,
				restDay:true,
				cateList:[],
				cateIndex:-1,
				storeData:[],
				headImg:"",
				proImg:[],
				info:{},
				moneyObj:{}
			}
		},
		onShow() {
			this.getCateList();
		},
		onLoad(options) {
			if(options.id){
				this.id = options.id;
				this.getDetails();
			}
			this.endTimes = app.$vm.getTime((new Date().getTime() + 24*60*60*1000*365),"-","day");
		},
		methods: {
			toIntro(){
				uni.navigateTo({
					url:"/pages/pageone/pages/About-us/About-us?index=7"
				})
			},
			toXy(){
				uni.navigateTo({
					url:"/pages/pageone/pages/About-us/About-us?index=5"
				})
			},
			changeGroup(e){
				let money = Number(e.detail.value);
				if(money<0.1){
					this.$refs.uToast.show({
						title:"团单售价最低为1元",
						type:"error",
						duration:2000
					})
					money = 1;
					setTimeout(()=>{
						this.formData.money = money;
						if(this.moneyObj.id){
							this.formData.user_commission_money = Number((money*Number(this.moneyObj.group_buying_percentage)/1000).toFixed(2));
							this.getSettleMoney();
						}
					},50)
				}
				if(this.moneyObj.id){
					this.formData.user_commission_money = Number((money*Number(this.moneyObj.group_buying_percentage)/1000).toFixed(2));
					this.getSettleMoney();
				}
				if(this.formData.user_commission_money>money*0.5){
					setTimeout(()=>{
						this.formData.user_commission_money = (money*0.5).toFixed(2);
						this.getSettleMoney();
						this.$refs.uToast.show({
							title:"分享最高金额为售价的50%",
							type:"error",
							duration:2000
						})
					},50)
				}
			},
			getSettleMoney(){
				console.log(this.formData.money,this.formData.user_commission_money)
				if(this.formData.money){
					this.settleMoney = this.formData.money - this.formData.user_commission_money - this.formData.money*this.moneyObj.group_procedures_percentage/1000;
				}else{
					this.settleMoney = 0;
				}
			},
			changeGroupMoney(e){
				let money = Number(e.detail.value);
				if(this.moneyObj.id){
					if(money<Number((Number(this.formData.money)*Number(this.moneyObj.group_buying_percentage)/1000).toFixed(2))){
						setTimeout(()=>{
							this.formData.user_commission_money = Number((Number(this.formData.money)*Number(this.moneyObj.group_buying_percentage)/1000).toFixed(2));
							this.getSettleMoney();
							this.$refs.uToast.show({
								title:"分享最低金额为"+this.formData.user_commission_money+"元",
								type:"error",
								duration:2000
							})
						},50)
					}else{
						if(money>Number(this.formData.money)*0.5){
							setTimeout(()=>{
								this.formData.user_commission_money = (Number(this.formData.money)*0.5).toFixed(2);
								this.getSettleMoney();
								this.$refs.uToast.show({
									title:"分享最高金额为售价的50%",
									type:"error",
									duration:2000
								})
							},50)
						}else{
							this.getSettleMoney();
						}
					}
				}else{
					this.getSettleMoney();
				}
			},
			getDetails(){
				let obj = {};
				obj.shop_package_id = this.id;
				obj.user_id = uni.getStorageSync("userId");;
				this.$u.api.shopPackageDetails(obj).then(res=>{
					//console.log(res)
					this.info = res.list;
					this.cateIndex = this.info.Shop.industry.id;
					// for(let i=0;i<this.cateList.length;i++){
					// 	if(this.cateList[i].id==this.info.Shop.industry.id){
					// 		this.cateIndex = i;
					// 	}
					// }
					// let shopArr = [];
					// for(let i=0;i<this.info.ShopPackageRelation.length;i++){
					// 	shopArr.push(this.info.ShopPackageRelation[i].Shop);
					// }
					let shopArr = [];
					shopArr.push(this.info.Shop);
					this.storeData = shopArr;
					this.formData.name = this.info.name;
					this.formData.money = Number(this.info.money);
					this.formData.user_commission_money = Number(this.info.user_commission_money);
					this.formData.remind = this.info.remind;
					this.tcList = JSON.parse(this.info.package_title);
					this.headImg = this.info.title_image;
					let imgArr = [];
					for(let i=0;i<this.info.images.length;i++){
						imgArr.push(this.info.images[i].image_url);
					}
					this.proImg = imgArr;
					this.richData = JSON.parse(this.info.content);
					if(this.info.stock_num>0){
						this.stockchecked = true;
						this.stockNum = this.info.num;
					}
					if(this.info.is_specified_time==0){
						this.Rdaiovalue = "相对时间";
						this.RdaioList[0].checked = true;
						this.days = Math.round(Number(this.info.effective_time)/24/60/60);
					}else{
						this.Rdaiovalue = "指定时间";
						this.RdaioList[1].checked = true;
						this.outTime = app.$vm.getTime(this.info.effective_time*1000,"-","day");
					}
					if(this.info.limit_time!=0){
						let limitObj = JSON.parse(this.info.limit_time);
						this.limitchecked = true;
						this.timeArrs = limitObj.val;
					}
					if(this.info.is_holidays==1){
						this.holiday = true;
					}
					if(this.info.is_rest==1){
						this.restDay = true;
					}
					if(this.info.personal_num>0){
						this.Singlechecked = true;
						this.buyNum = this.info.personal_num;
					}
					if(this.info.is_appointment==1){
						this.makechecked = true;
					}
					if(this.info.use_num==0){
						this.useNum = "不限人数";
						this.useNumList[0].checked = true;
					}else{
						this.useNum = "指定人数";
						this.useNumList[1].checked = true;
						this.userNum = this.info.use_num;
					}
					if(this.info.is_discount_share==1){
						this.discountBy = true;
					}
					let funArr = [];
					for(let i=0;i<shopArr.length;i++){
						funArr.push(this.getCityMoney(shopArr[i].city_id))
					}
					Promise.all(funArr).then(res=>{
						let obj = {};
						obj.group_buying_percentage = Number(res[0].data.group_buying_percentage);
						obj.group_procedures_percentage = Number(res[0].data.group_procedures_percentage);
						obj.id = 1;
						for(let i=0;i<res.length;i++){
							if(res[i].data.group_buying_percentage > obj.group_buying_percentage){
								obj.group_buying_percentage = res[i].data.group_buying_percentage;
							}
							if(res[i].data.group_procedures_percentage > obj.group_procedures_percentage){
								obj.group_procedures_percentage = res[i].data.group_procedures_percentage;
							}
						}
						this.moneyObj = obj;
						if(this.formData.money){
							if(this.formData.user_commission_money){
								if(Number((Number(this.formData.money)*Number(obj.group_buying_percentage)/1000).toFixed(2))>Number(this.formData.user_commission_money)){
									this.formData.user_commission_money = Number((Number(this.formData.money)*Number(obj.group_buying_percentage)/1000).toFixed(2));
									this.$refs.uToast.show({
										title:"最低分享佣金为"+this.formData.user_commission_money+"元",
										type:"error",
										duration:2000
									})
								}
							}else{
								this.formData.user_commission_money = Number((Number(this.formData.money)*Number(obj.group_buying_percentage)/1000).toFixed(2));
								this.$refs.uToast.show({
									title:"已为您适配分享佣金,请留意",
									type:"success",
									duration:2000
								})
							}
						}
						this.getSettleMoney();
					})
					
					
				})
			},
			getCityMoney(id){
				return new Promise((resolve,reject)=>{
					this.$u.api.areaDetails({id:id}).then(res=>{
						resolve(res)
					})
				})
			},
			restDaySwitchBtn(e){
				
			},
			holidaySwitchBtn(e){
				
			},
			discountByBtn(e){
				
			},
			delImg(e){
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				this.proImg.splice(index,1);
			},
			getImage(url){
				if(url&&(url.indexOf("http://")!=-1||url.indexOf("https://")!=-1)){
					return url;
				}else{
					return app.$vm.globalData.imgBaseUrl + url;
				}
			},
			uploadProImg(){
				let _this = this;
				uni.chooseImage({
				    count: 9, //默认9
				    sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album'], //从相册选择
				    success: function (result) {
						uni.showLoading({
							title:"上传图片中..."
						})
						let j = result.tempFilePaths.length;
						let arr = JSON.parse(JSON.stringify(_this.proImg))
						let p = arr.length;
						for(let i=0;i<result.tempFilePaths.length;i++){
							_this.proImg.push("");
						}
						for(let i=0;i<result.tempFilePaths.length;i++){
							app.$vm.updataAvator(result.tempFilePaths[i]).then(res=>{
								j--;
								_this.proImg.splice((p+i),1,res)
								if(j==0){
									uni.hideLoading();
								}
							});
						}
				    },
					fail:err=>{
						if(err.errMsg!='chooseImage:fail cancel'){
							app.$vm.checkAuth("scope.camera").then(resultConfirm=>{
								if(resultConfirm){
									uni.showModal({
										title:"系统繁忙，请稍后再试"
									})
								}else{
									uni.showModal({
										title:"请检查摄像头和相册权限后重试"
									})
								}
							})
						}
					}
				});
			},
			uploadHeadImg(){
				let _this = this;
				uni.chooseImage({
					count:1,
					sizeType:["compressed"],
					success(result) {
						app.$vm.updataAvator(result.tempFilePaths[0]).then(res=>{
							//console.log(res)
							_this.headImg = res;
						});
					},
					fail:err=>{
						if(err.errMsg!='chooseImage:fail cancel'){
							app.$vm.checkAuth("scope.camera").then(resultConfirm=>{
								if(resultConfirm){
									uni.showModal({
										title:"系统繁忙，请稍后再试"
									})
								}else{
									uni.showModal({
										title:"请检查摄像头和相册权限后重试"
									})
								}
							})
						}
					}
				})
			},
			submit(){
				let obj = this.formData;
				if(!this.Radiochecked){
					this.$refs.uToast.show({
						title:"请先阅读并同意《商户服务协议》",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(!obj.name){
					this.$refs.uToast.show({
						title:"请输入团单名称",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(!obj.money){
					this.$refs.uToast.show({
						title:"请输入团单售价",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(!obj.user_commission_money&&obj.user_commission_money!==0&&obj.user_commission_money!=='0'){
					this.$refs.uToast.show({
						title:"请输入分销佣金",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(this.storeData.length==0){
					this.$refs.uToast.show({
						title:"请选择使用门店",
						type:"error",
						duration:2000
					})
					return false;
				}
				
				let proArr = [];
				for(let i=0;i<this.tcList.length;i++){
					if(this.tcList[i].name){
						let proArr2 = {};
						proArr2.name = this.tcList[i].name;
						let arrP = []
						for(let j=0;j<this.tcList[i].conList.length;j++){
							if(this.tcList[i].conList[j].name&&(this.tcList[i].conList[j].price>0||this.tcList[i].conList[j].price===0||this.tcList[i].conList[j].price==='0')){
								arrP.push(this.tcList[i].conList[j]);
							}
						}
						proArr2.conList = arrP;
						proArr.push(proArr2)
					}
				}
				console.log(JSON.stringify(proArr))
				console.log(JSON.stringify(this.tcList))
				obj.package_title = JSON.stringify(proArr);
				obj.content = JSON.stringify(this.richData);
				if(!this.headImg){
					this.$refs.uToast.show({
						title:"请上传团单头图",
						type:"error",
						duration:2000
					})
					return false;
				}
				obj.title_image = this.headImg;
				if(this.stockchecked){
					if(!this.stockNum){
						this.$refs.uToast.show({
							title:"库存至少为1",
							type:"error",
							duration:2000
						})
						return false;
					}
					if(this.info.use_num){
						obj.stock_num = Number(this.stockNum) + Number(this.info.use_num);
					}else{
						obj.stock_num = Number(this.stockNum);
					}
					obj.num = this.stockNum;
				}else{
					obj.stock_num = 0;
				}
				if(this.Rdaiovalue == "相对时间"){
					obj.is_specified_time = 0;
					if(!this.days){
						this.$refs.uToast.show({
							title:"请输入相对天数",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.effective_time = Number(this.days)*24*60*60;
				}else if(this.Rdaiovalue == "指定时间"){
					obj.is_specified_time = 1;
					if(!this.outTime){
						this.$refs.uToast.show({
							title:"请选择指定日期",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.effective_time = Math.floor(new Date(this.outTime).getTime()/1000);
				}else{
					this.$refs.uToast.show({
						title:"请选择团单有效期",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(this.ShelfValue=="指定时间"){
					if(!this.putOnTheShelfTime){
						this.$refs.uToast.show({
							title:"请选择指定上架日期",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.online_time = Math.floor(new Date(this.putOnTheShelfTime).getTime()/1000);
				}else if(this.ShelfValue=="提交成功立即上架"){
					obj.online_time = Math.floor(new Date().getTime()/1000);
					obj.is_upper_frame = 1;
				}else{
					this.$refs.uToast.show({
						title:"请选择上架时间",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(this.OffshelfValue=="指定时间"){
					if(!this.offTheShelfTime){
						this.$refs.uToast.show({
							title:"请选择指定下架日期",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.offline_time = Math.floor(new Date(this.offTheShelfTime).getTime()/1000);
				}else if(this.OffshelfValue=="自动延期保持上架"){
					obj.offline_time = 0;
				}else{
					this.$refs.uToast.show({
						title:"请选择下架时间",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(this.limitchecked){
					if(!this.timeArrs||this.timeArrs.length==0){
						this.$refs.uToast.show({
							title:"请选择使用时间段",
							type:"error",
							duration:2000
						})
						return false;
					}
					let objTime = {};
					objTime.str = this.timeList[0][this.timeArrs[0]]+" "+'-'+" "+this.timeList[1][this.timeArrs[1]];
					objTime.val = this.timeArrs;
					obj.limit_time = JSON.stringify(objTime)
				}else{
					obj.limit_time = 0;
				}
				if(this.holiday){
					obj.is_holidays = 1;
				}else{
					obj.is_holidays = 0;
				}
				if(this.restDay){
					obj.is_rest = 1;
				}else{
					obj.is_rest = 0;
				}
				if(this.Singlechecked){
					if(!this.buyNum){
						this.$refs.uToast.show({
							title:"请填写单人购买量限制数量",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.personal_num = this.buyNum;
				}else{
					obj.personal_num = 0;
				}
				if(this.makechecked){
					obj.is_appointment = 1;
				}else{
					obj.is_appointment = 0;
				}
				if(this.useNum=="指定人数"){
					if(!this.userNum){
						this.$refs.uToast.show({
							title:"请填写指定使用人数",
							type:"error",
							duration:2000
						})
						return false;
					}
					obj.use_num = this.userNum;
				}else if(this.useNum=="不限人数"){
					obj.use_num = 0;
				}else{
					this.$refs.uToast.show({
						title:"请选择使用人数",
						type:"error",
						duration:2000
					})
					return false;
				}
				if(this.discountBy){
					obj.is_discount_share = 1;
				}else{
					obj.is_discount_share = 0;
				}
				obj.money = this.formData.money;
				obj.name = this.formData.name;
				obj.user_commission_money = this.formData.user_commission_money;
				obj.remind = this.formData.remind;
				//   obj.user_id = this.user_id;
				obj.id = this.id;
				obj.user_id = uni.getStorageSync("userId");;
				obj.shopids = [];
				
				for(let i=0;i<this.storeData.length;i++){
					obj.shopids.push(this.storeData[i].id);
				}
				let imArrs = [];
				for(let i=0;i<this.proImg.length;i++){
					imArrs.push({image_url:this.proImg[i]})
				}
				obj.images = imArrs;
				
				console.log(obj)
				if(this.id){
					// obj.userids = this.id;
					this.$u.api.shopPackageEdit(obj).then(res=>{
						//console.log(res)
						this.$refs.uToast.show({
							title:"发布成功",
							type:"success",
							duration:2000
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1500)
						
					})
				}else{
					// obj.images = newObj.images;
					// obj.shop_id = newObj.shop_id;
					this.$u.api.shopPackageAdd(obj).then(res=>{
						//console.log(res)
						this.$refs.uToast.show({
							title:"发布成功",
							type:"success",
							duration:2000
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1500)
						
					})
				}
			},
			choiceCate(e){
				this.cateIndex = e.detail.value;
			},
			getCateList(){
				this.$u.api.industryList().then(res=>{
					//console.log(res)
					this.cateList = res.data;
					if(this.info.id){
						for(let i=0;i<this.cateList.length;i++){
							if(this.cateList[i].id==this.info.id){
								this.cateIndex = i;
							}
						}
					}
				})
			},
			toAddStore(){
				if(this.cateIndex==-1){
					this.$refs.uToast.show({
						title:"请先选择领域",
						type:"error",
						duration:2000
					})
					return false;
				}
				uni.setStorageSync("storeData",this.storeData);
				uni.navigateTo({
					url:"/pages/pageone/pages/choiceStore/choiceStore?type=auth&id="+this.cateList[this.cateIndex].id
				})
			},
			putOnTheShelf(e){
				this.putOnTheShelfTime = e.detail.value;
			},
			offTheShelf(e){
				this.offTheShelfTime = e.detail.value;
			},
			timSlotChange(e){
				console.log(e)
				this.timeArrs = e.detail.value;
				// this.timeSlot = e.detail.value;
			},
			useNumChange(e){
				console.log(e)
				// this.useNum = e.detail.value;
			},
			selectOutTime(e){
				this.outTime = e.detail.value;
			},
			addCon(e) {
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				let arr = this.tcList;
				arr[index].conList.push({
					name: "",
					price: ""
				});
				this.tcList = arr;
			},
			delCon(e) {
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				let pindex = e.target.dataset.pindex || e.currentTarget.dataset.pindex;
				let arr = this.tcList;
				arr[index].conList.splice(pindex, 1);
				this.tcList = arr;
			},
			delTc(e){
				let index = e.target.dataset.index || e.currentTarget.dataset.index;
				let arr = this.tcList;
				arr.splice(index,1);
				this.tcList = arr;
			},
			addProject() {
				let obj = {};
				obj.name = "";
				obj.conList = [{
					name: "",
					price: ""
				}];
				let arr = this.tcList;
				arr.push(obj);
				this.tcList = arr;
			},
			//图文介绍
			toGraphicIntroduction() {
				if(this.richData.richTxt){
					uni.setStorageSync("richData",this.richData)
				}else{
					uni.removeStorageSync("richData")
				}
				uni.navigateTo({
					url: "/pages/pagetwo/pages/GraphicIntroduction/GraphicIntroduction"
				})
			},
			//底部单选框
			selectRadio() {
				// console.log(this.Radiochecked);
				this.Radiochecked = !this.Radiochecked;
				
			},
			// 下架时间选择框
			radioOffshelftime(e) {
				console.log(e);
			},
			// 上架时间选择框
			radioShelf(e) {
				console.log(e);
			},
			// 有效期选择框
			radioChange(e) {
				console.log(e);
			},
			//预约
			makeswitchBtn(status) {
				console.log(status);
			},
			//单人购买
			SingleswitchBtn(status) {
				console.log(status);
			},
			//时间限制滑块
			limitswitchBtn(status) {
				console.log(status);
			},
			//库存滑块
			stockswitchBtn(status) {
				console.log(status);
			}
		}
	}
</script>

<style scoped lang="less">
	.GroupOrder {
		background-color: #F3F3F3;
		min-height: 100vh;
		// overflow: auto;

		.GroupOrderBox {
			padding-bottom: 230upx;
			//基础信息开始
			.BasicsBox {
				.Basicstitle {
					font-size: 20upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #999999;
					padding: 16upx 24upx;
				}

				.Basics {
					width: 750upx;
					background-color: #fff;
					padding: 0 24upx;

					.BasicsItem {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EFEFEF;

						.BasicsName {
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.Basics_R {
							display: flex;
							align-items: center;

							.Basicstype {
								font-size: 24upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #333333;
								margin-right: 8upx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}
						}
					}
				}
			}

			// 基础信息结束
			// 商品信息开始
			.commodityBox {
				.commoditytitle {
					font-size: 20upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #999999;
					padding: 16upx 24upx;
				}

				.commodityInfo {
					padding: 0 24upx;
					background-color: #fff;

					.commodityNameBox {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EFEFEF;

						.commodityName {
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.commodity_R {
							display: flex;
							align-items: center;

							.commoditytext {
								font-size: 24upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #333333;
								margin-right: 8upx;
							}
						}
					}

					.service {
						font-size: 28upx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
						padding: 32upx 0;
						display: flex;
						justify-content: space-between;
					}

					.uploadBox {
						margin-bottom: 16upx;
						.tcItem {
							padding-bottom: 20upx;
							border-bottom: 2upx solid #EFEFEF;
							margin-bottom: 20upx;
							.tcItemT {
								display: flex;
								align-items: center;
								justify-content: space-between;
								align-items: center;
								padding: 0 30upx;
								box-sizing: border-box;

								input:nth-child(2) {
									width: calc(100% - 360upx);
									height: 60upx;
									box-sizing: border-box;
									border: 2upx solid #808080;
									border-radius: 8upx;
									padding: 0 24upx;
								}

								text:nth-child(3) {
									color: red;
									margin-left: 30upx;
								}
							}

							.tcItemB {
								box-sizing: border-box;
								padding: 0 30upx;
								margin-top: 30upx;

								.tcItemBItem {
									// padding: 0 30upx;
									display: flex;
									align-items: center;
									justify-content: space-between;
									margin-bottom: 20upx;

									input {
										width: 42%;
										height: 60upx;
										box-sizing: border-box;
										border: 2upx solid #808080;
										border-radius: 8upx;
										padding: 0 24upx;
									}

									text {
										color: red;
									}
								}
							}
						}
					}
					.uploadBoxs{
						width: 112upx;
						height: 112upx;
						border-radius: 8upx;
						border: 2upx dashed #707070;
						display: flex;
						align-items: center;
						justify-content: center;
						box-sizing: border-box;
						.uploadIcon{
							width: 48upx;
							height: 48upx;
						}
					}
					.priceBox {
						display: flex;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EFEFEF;

						.priceName {
							width: 112upx;
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.price_R {
							display: flex;
							align-items: center;
							width: calc(100% - 112upx);

							input {
								width: 100%;
								font-size: 24upx;
								padding-right: 16upx;
								text-align: right;
								// direction: rtl
							}
						}
					}

					.tips {
						font-size: 20upx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #FF5555;
						padding: 24upx 0 32upx 0;
					}

					.Head-diagram {
						font-size: 28upx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
					}

					.tips_text {
						font-size: 20upx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
						padding: 24upx 0;
					}
					
					.uploadProImg{
						display: flex;
						flex-wrap: wrap;
						view{
							width: 112upx;
							// height: 112upx;
							border-radius: 8upx;
							margin-right: 6upx;
						}
						>view:nth-child(6n+6){
							margin-right: 0;
						}
						.imgBoxWrap{
							width: 112upx;
							height: 112upx;
							border-radius: 8upx;
							background-position: center;
							background-size: cover;
						}
					}

					.uploadBox {
						margin-bottom: 16upx;
					}
				}
			}

			// 商品信息结束
			// 购买须知开始
			.NoticeBox {
				.Noticetitle {
					font-size: 20upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #999999;
					padding: 16upx 24upx;
				}

				.NoticeInfo {
					background-color: #fff;
					padding: 0 24upx;

					.stockBox {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EFEFEF;

						.stocktitle {
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.switchBox {}
					}

					.validityBox {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EDEDED;

						.validitytitle {
							// width: 112upx;
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.radioBox {}
					}

					.ordertitmeBox {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 16upx 0 32upx 0;

						.orderName {
							font-size: 24upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #999999;
						}

						.ordertitme {
							font-size: 24upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}
					}

					.OffshelftimeBox {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 32upx 0;
						border-bottom: 2upx solid #EFEFEF;

						.OffshelftimeName {
							font-size: 28upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}

						.Offshelftime_R {
							display: flex;
							align-items: center;

							.Offshelftimetext {
								font-size: 24upx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #333333;
							}
						}
					}
				}
			}

			// 购买须知结束
			.SubmitBox {
				position: fixed;
				bottom: 0;
				width: 750upx;
				height: 204upx;
				background: #FFFFFF;
				opacity: 1;
				padding: 24upx;
				z-index: 9999;
				border-top: 2upx solid #EFEFEF;

				.RadioBox {
					font-size: 24upx;
					color: #333333;

					.radio {}
				}

				.SubmitBtn {
					width: 702upx;
					height: 100upx;
					background: #FFAC3F;
					border-radius: 8upx;
					font-size: 28upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					line-height: 100upx;
					text-align: center;
					color: #FFFFFF;
					margin-top: 24upx;
				}
			}
		}
	}
</style>
